<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<%@include file="../../public/commonJs.jsp" %>
<%@include file="../../public/commonCss.jsp" %>
<div id="myform" style="background-color: #fff" ms-controller="main">
    <div style="width:100%;height:100%;overflow:auto;background-color: #fff;padding-top:15px;">
        <div class="layui-form-item" style="margin-left: 80px;">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="fontRed">*</span>菜单名称：</label>
                <div class="layui-input-inline" style="width: 150px;">
                    <input type="text" class="inputText" style="height:32px" placeholder="" ms-duplex="menu.name"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 80px;">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="fontRed">*</span>菜单url：</label>
                <div class="layui-input-inline" style="width: 150px;">
                    <input type="text" class="inputText" style="height:32px" placeholder="" ms-duplex="menu.url">
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 80px;">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="fontRed">*</span>菜单logo：</label>
                <div class="layui-input-inline" style="width: 150px;">
                    <input type="text" class="inputText" style="height:32px" placeholder="" ms-duplex="menu.logoUrl">
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 80px;">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="fontRed">*</span>上级菜单：</label>
                <select style="width: 150px;" ms-duplex="menu.parentId">
                    <option value="root">--请选择上级菜单--</option>
                    <option ms-attr-value="el.id" ms-repeat="parentMenus">{{el.name}}</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 80px;">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="fontRed">*</span>菜单排序：</label>
                <input type="text" class="inputText" style="height:32px" placeholder="" ms-duplex="menu.sortOrder">
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 80px;">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="fontRed">*</span>菜单分类：</label>
                <select style="width: 150px;" ms-duplex="menu.type">
                    <option value="">--请选择菜单分类--</option>
                    <option value="1">功能</option>
                    <option value="0">目录</option>
                </select>
            </div>
        </div>
        <!-- content -->
        <div class="bottomButton moveArea" style="display:block;position:absolute;bottom:0;">
            <button class="layui-btn" ms-on-click="saveOrUpdate()">保存</button>
            <button class="layui-btn layui-btn-primary" ms-on-click="closeLayer()">取消</button>
        </div>
    </div>
</div>
<script type="text/javascript">
    var vm;
    $(function () {
        vm = avalon.define({
            $id: "main",
            menu: {
                id: '${menu.id}',
                url: '${menu.url}',
                logoUrl: '${menu.logoUrl}',
                name: '${menu.name}',
                parentId: '${menu.parentId}',
                sortOrder: '${menu.sortOrder}',
                type: '${menu.type}'
            },
            parentMenus: []
        });
        loadDataMap();
    });
    //加载下拉框数据
    function loadDataMap() {
        $.ajax({
            type: 'post',
            url: '${ctx}/menuController/selectDataMap.action',
            data: '',
            dataType: "json",
            timeout: 10000,
            success: function (data) {
                if (data.code == 0) {
                    vm.parentMenus = data.datas;
                }
            }
        });
    }

    //保存或者更新
    function saveOrUpdate() {
        var dataStr = $.param(vm.$model.menu);
        $.ajax({
            type: 'post',
            url: '${ctx}/menuController/saveOrUpdate.action',
            data: dataStr,
            dataType: "json",
            timeout: 10000,
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.closeAll();
                    parent.layer.msg('保存成功', {icon: 1});
                    parent.loadTableData();
                } else {
                    parent.layer.msg('保存失败', {icon: 2});
                }
            }
        });
    }
    //关闭对话框
    function closeLayer() {
        parent.layer.closeAll();
    }
</script>
